package network;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;

/**
 * <p>
 *
 * </p>
 *
 * @author LovelyBigDuck
 * @date 2021/5/24 19:34
 */
public class UdpClient {
    public static void main(String[] args) throws IOException {
        String host = "localhost";
        int port = 8888;
        InetSocketAddress socketAddress = new InetSocketAddress(host, port);
        DatagramSocket socket = new DatagramSocket();


        String msg = "hello world";
        byte[] data = msg.getBytes(StandardCharsets.UTF_8);

        DatagramPacket datagramPacket = new DatagramPacket(data, data.length, socketAddress);
        socket.send(datagramPacket);
        System.out.println("消息发送成功");
    }

}